package org.dna.wicketui.activities;

import java.util.Collections;
import java.util.List;

import org.apache.log4j.Logger;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;
import org.dna.uimodel.MenuItem;
import org.dna.uimodel.SelectableActivity;
import org.dna.wicketui.MetroPage;

/**
 * Page used to create a new or modify an existing activity.
 * */
public class ManageActivityPage extends MetroPage {

    private static final Logger LOG = Logger.getLogger(ManageActivityPage.class);

//    @UserRoles({"admin", "user"})
//    private class ListActivityLink extends Link<Void> {
//
//        private static final long serialVersionUID = 4258377978719477979L;
//
//        public ListActivityLink(String id) {
//            super(id);
//        }
//
//        @Override
//        public void onClick() {
//            switchToPanel(ActivityListPanel.class);
//        }
//
//        @Override
//        public boolean isEnabled() {
//            return m_currentPanel instanceof ActivityDetailsPanel;
//        }
//    }

//    /**
//     * Sets the current activity to be displayed by this page, force the showing
//     * of ActivityDetailsPanel with the given activity.
//     * */
//    public void setCurrentActivity(Activity act) {
//        switchToPanel(ActivityDetailsPanel.class, act);
//    }

    @Override
    protected Panel configurePanels() {
        IModel<List<SelectableActivity>> allActivitiesModel = new LoadableDetachableModel<List<SelectableActivity>>() {

            @Override
            protected List<SelectableActivity> load() {
                return allActivities();
            }
        };
//       ActivityDetailsPanel activityDetailsPanel = new ActivityDetailsPanel("innerPanel");
        ActivityListPanel activityListPanel = new ActivityListPanel("innerPanel",
                allActivitiesModel);

//        m_panelsMap.put(ActivityDetailsPanel.class, activityDetailsPanel);
        m_panelsMap.put(ActivityListPanel.class, activityListPanel);
        return activityListPanel;
    }

    @Override
    protected List<MenuItem> preparePageContextMenu() {
//        MenuItem allActivitiesItem = new MenuItem("All activities", ManageActivityPage.class) {
//
//            @Override
//            public Component createMenu() {
//                ListActivityLink link = new ListActivityLink("link");
//                link.add(new Label("caption", getCaption()));
//                return link;
//            }
//        };
//        return Arrays.asList(allActivitiesItem);
        return Collections.EMPTY_LIST;
    }
}
